package com.mls.fivedistrict.common;


import com.mls.fivedistrict.pojo.ManagerUser;
import com.mls.fivedistrict.pojo.User;

import javax.servlet.http.HttpServletRequest;

public class RequestHolder {

    private static final ThreadLocal<User> userHolder = new ThreadLocal<User>();
    private static final ThreadLocal<ManagerUser> managerUserHolder = new ThreadLocal<ManagerUser>();
    private static final ThreadLocal<String> tokenHolder = new ThreadLocal<String>();

    private static final ThreadLocal<PageFilter> pageFilterHolder = new ThreadLocal<PageFilter>();

    private static final ThreadLocal<HttpServletRequest> requestHolder = new ThreadLocal<HttpServletRequest>();

    public static void add(User user) {
        userHolder.set(user);
    }

    public static void add(HttpServletRequest request) {
        requestHolder.set(request);
    }

    public static void add(String token) {
        tokenHolder.set(token);

    }
    public static void add(ManagerUser managerUser) {
        managerUserHolder.set(managerUser);

    }
    public static void add(PageFilter pageFilter) {
        pageFilterHolder.set(pageFilter);
    }

    public static User getCurrentUser() {
        return userHolder.get();
    }

    public static HttpServletRequest getCurrentRequest() {
        return requestHolder.get();
    }
    public static ManagerUser getManagerUser() {
        return managerUserHolder.get();
    }

    public static String getToken() {
        return tokenHolder.get();
    }

    public static PageFilter getPageFilter() {
        return pageFilterHolder.get();
    }

    public static void remove() {
        userHolder.remove();
        requestHolder.remove();
        tokenHolder.remove();
        pageFilterHolder.remove();
        managerUserHolder.remove();

    }
}
